<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>授权</title>
    
      <link href="images/skin.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
	body{
		margin:0;
		padding:0;
	}
	#top{
		width: 100%;
		height: 63px;
	}
	#left{
		position: absolute;
		left: 0;
		top: 65px;
		width:185px;

	}
	#right{
		position: absolute;
		left: 186px;
		top: 65px;
		width: 1100px;
	}
	</style>
    
     <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
     <script type="text/javascript" >
     <!--
     	$(document).ready(function(){
     		rid = ${id};
     	//	alert(rid);
     		$.ajax({
  	  			type: 'post',
  	  			url: 'goAuthorization.action',
  	  			data: {id: rid},
  	  			dataType:'xml',
  	  			success: function(xml){
  	  				var result="<table border='1px'><tr>";
  	  				var i=0;
  	  				$(xml).find("permission").each(function(){
  	  					i++;
  	  					if($(this).children("check").text() == "y")
  	  						result += "<td><input type='checkbox' checked='checked'  name='permissionIds' value='"+$(this).children("id").text()+"' />"+$(this).children("name").text()+"</td>";
  	  					else
  	  						result += "<td><input type='checkbox' name='permissionIds' value='"+$(this).children("id").text()+"' />"+$(this).children("name").text()+"</td>";
  	  				//	alert($(this).children("id").text());
  	  					if(i%4 == 0)
  	  						result += "</tr><tr>";
  	  				});
  	  				result += "</tr></table>";
  	  				$("#authDiv").html(result);
  	  			}
  	  		});
     		
     		$("#submitBtn").click(function(){
     			var rid = $("#roleId").val();
     			var chk_ids ="";    
	   			$("input[name='permissionIds']:checked").each(function(){    
	   			 	chk_ids += $(this).val() + ",";
	   			});    
	   			if(chk_ids == ""){
	   				alert("请选择权限！");
	   				return;
	   			}else
	   				chk_ids += "0";
	   			$.ajax({
	   				type: 'post',
	   				url: 'authorize.action',
	   				data: {roleId: rid, ids: chk_ids},
	   				success: function(){
	   					alert('successful');
		  				window.location.href='listAllRoles.action';
	   				}
	   			});
     		});
     			
     		
     	});
     //-->
     </script>

  </head>
  
  <body>
  <div id="top"><jsp:include page="/WEB-INF/page/top.jsp"></jsp:include></div>
  <div id="left"><jsp:include page="/WEB-INF/page/lef.jsp"></jsp:include></div>
  <div id="right">
  
  <table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="17" valign="top" background="images/mail_leftbg.gif"><img src="images/left-top-right.gif" width="17" height="29" /></td>
    <td valign="top" background="images/content-bg.gif"><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="left_topbg" id="table2">
      <tr>
        <td height="31"><div class="titlebt">授权</div></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td valign="middle" background="images/mail_leftbg.gif">&nbsp;</td>
    <td valign="top" bgcolor="#F7F8F9"><table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td colspan="2" valign="top">&nbsp;</td>
        <td>&nbsp;</td>
        <td valign="top">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="2" valign="top"><span class="left_bt"></span><br/>
			角色名：${role.name }
   <div id="authDiv">
   	
   </div>
   <input type="hidden" name="roleId" id="roleId" value="${role.id }"/>
   <input type="button" id="submitBtn" value="确定"/>
  <input type="button" onclick="window.history.go(-1)" value="返回"/>
			
        </td>
          </tr>
 
  </div>
  </body>
</html>